// pages/myplan/myplan.js
const app = getApp()
Page({
  data: {
    list: [],
    height: 800,
    showModal:false,
    dialogTitle:'',
    dialogContent:''
  },
  onLoad: function (options) {
    //hgz/demand/queryListWithPage
    var windowHeight = app.globalData.windowHeight;
    this.setData({
      height: windowHeight-80
    })
  },
  onShow(){
    var params = {
      pageNum: 1,
      pageSize: 1000
    }
    app.request.postHeadForm('hgz/post/queryListWithPage', params)
      .then(res => {
        var dataList = res.data.list;
        this.setData({
          list: dataList
        })
      })
  },
  detail(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/luntandetail/luntandetail?id=' + id,
    })
  },
  onConfirm() {
    var params ={
      title: this.data.dialogTitle,
      content: this.data.dialogContent,
    }
    if(this.data.dialogTitle == ''){
      wx.showToast({
        title: '标题不能为空',
        icon: 'none',
        duration: 1000
      })
      return;
    }
    if (this.data.dialogContent == '') {
      wx.showToast({
        title: '内容不能为空',
        icon: 'none',
        duration: 1000
      })
      return;
    }
    wx.showLoading({
      title: '加载中',
    })
    app.request.postHeadJson('hgz/post/save', params).then(res =>{
      wx.hideLoading();
      if(res.status){
        wx.showToast({
          title: '发帖成功',
          icon: 'none',
          duration: 1000
        })
        this.onShow();
        this.setData({
          showModal: false
        })
      }else{
        wx.showToast({
          title: ''+res.message,
          icon: 'none',
          duration: 1000
        })
      }
    })

  },
  submit(){
    this.setData({
      showModal: true
    })
  },
  inputChange1(e){
    this.setData({
      dialogTitle: e.detail.value
    })
  },
  inputChange2(e) {
    this.setData({
      dialogContent: e.detail.value
    })
  },
  onCancel(){
    this.setData({
      showModal: false
    })
  },
  preventTouchMove: function () {

  }

})